<!DOCTYPE html>
<html>

{include file='public/header'}
<style>
    /* .layui-input-block{margin-left: 90px;} */
    .layui-table-cell {
        height: auto!important;
    }
    .layui-input-block{
        margin-left: 90px;
    }
</style>
<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="javascript:void(0)">首页</a>
            <a href="javascript:void(0)">分销中心</a>
            <a><cite>分销商分成统计列表</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" id="reload" title="刷新">
            <i class="layui-icon" style="line-height:30px"><i class="iconfont">&#xe6aa;</i></i>
        </a>
    </div>
    <div class="x-body">
        <form class="layui-form" lay-filter="searchForm">
            <div class="layui-inline">
                <label class="layui-form-label w-auto">分销商：</label>
                <div id="pMenu"></div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label w-auto">日期：</label>
                <div class="layui-inline" id="time" style="display: flex;align-items: center;">
                    <div class="layui-input-inline" style="margin-right:10px">
                        <input type="text" class="layui-input" name="start_date" id="start_date" autocomplete="off" placeholder="开始时间">
                    </div>
                    <div class="layui-form-mid">-</div>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="end_date" id="end_date" autocomplete="off" placeholder="结束日期">
                    </div>
                </div>
            </div>
            <!-- <div class="layui-inline">
                <label class="layui-form-label w-auto">选择短剧：</label>
                <div id="pMenu1" style="width:100%;flex:1"></div>
            </div> -->
            <div class="layui-inline">
                <button class="layui-btn" style="margin-left: 10px;" lay-submit lay-filter="searchList">搜索</button>
                <button type="reset" id="resetList" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </form>
        <table id="distribution" lay-filter="distribution"></table>
    </div>
    
    <script>
        let totalObj = {}
        let params = {
            elem: '#distribution'
            , toolbar: true
            , url: '/admin/distribution/list' //数据接口
            , id: 'distribution'
            , page: true
            , limit:15
            , totalRow:true
            , cols: [[ //表头
                { field: 'date', title: '日期',align:'center' ,totalRowText: '总合计：' }
                , { field: 'company_name', title: '公司名称' ,align:'center' }
                , { field: 'name', title: '负责人名称',align:'center' }
                , { field: 'recharge_price', title:'总充值金额', align:'center'}
                , { field: 'refund_price', title:'总退款金额', align:'center'}
                , { field: 'commission', title: '总支付通道费', align:'center',width:120}
                , { field: 'sharing_amount', title: '分销商<br />分成金额', align:'center', width:140 }
                , { field: 'ly_sharing_amount', title: '比翼鸟<br />分成金额', align:'center', width:140 }
                , { field: 'virtual_recharge_price', title:'虚拟支付<br />充值金额', align:'center', width:140}
                , { field: 'virtual_refund_price', title:'虚拟支付<br />退款金额', align:'center', width:140}
                , { field: 'virtual_commission', title:'虚拟支付<br />通道费(0.8%)', align:'center', width:140}
                , { field: 'virtual_amount', title:'虚拟支付<br />分成金额(80%)', align:'center', width:140}
                , { field: 'common_recharge_price', title:'非虚拟支付<br />充值金额', align:'center', width:140}
                , { field: 'common_refund_price', title:'非虚拟支付<br />退款金额', align:'center', width:140}
                , { field: 'common_commission', title:'非虚拟支付<br />通道费(0.8%)', align:'center', width:140}
                , { field: 'common_amount', title:'非虚拟支付<br />分成金额(85%)', align:'center', width:140}
                , { field: 'ad_incentive_amount', title:'腾讯广告<br />激励金', align:'center', width:120}
            ]],
            customTotal:function(){
                let that = this;
                layui.use('form', function () {
                    getTotal('/admin/distribution/divideIntoTotal',totalObj).then(val=>{
                        totalObj = val
                    })
                });
            },
            done:function(){
                setPrice(totalObj)
            }
        }
        tableList(params)

        layui.use('laydate', function () {
            var laydate = layui.laydate
            // 日期
            laydate.render({
                elem: '#time',
                range: ['#start_date', '#end_date'],
                format: 'yyyy-MM-dd'
            });
        })

        function setPrice(totalObj){
            Object.keys(totalObj).forEach(item=>{
                $(`.layui-table-total td[data-field=${item}] .layui-table-cell`).text(totalObj[item]);
            })
        }

        let selectParams = {
            url: '/admin/distribution/selectList',
            elem: '#pMenu',
            selected: [],
            tips: '选择分销商',
            name: 'distributor_id',
            field_id: 'id',
            field_Name: 'name',
        }
        selectN(selectParams)

        // let selectParams1 = {
        //     url: '/admin/video/select',
        //     selected: [],
        //     tips: '选择短剧',
        //     name: 'video_id',
        //     field_id: 'id',
        //     field_Name: 'name',
        //     elem: '#pMenu1',
        //     search:true
        // }
        // selectN(selectParams1)
    </script>
</body>

</html>